package com.ruoyi.system.outto.goods.impl;


import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.ImgUntil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.dto.yx7881.bean.*;
import com.ruoyi.system.outto.dto.yx7881.core.LieBaoCore;
import com.ruoyi.system.outto.goods.MONI7881Api;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
@Service
public class MONI7881ApiImpl implements MONI7881Api {

    @Resource
    private IGameAttributeService gameAttributeService;
    @Resource
    InterAttrMapper interAttrMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;

    final String DefaultV = "无";

    //参数
    private void Property(Map<String,Object> params, GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
//        goodsBean.setGameId(interAttr.getInterGameId());
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto, params, interAttr.getRadioAttr());
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto, params, interAttr.getCheckAttr());
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto, params, interAttr.getInputAttr());
    }

    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map<String,Object> params, String radioAttr) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            throw new GlobalException("接口单选属性暂未配置");
        }
        /**
         * 1、先查询自定义中所有单选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        gameAttrTemplate.setFieldType("radio");
        List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();


        List<JSONObject> defObjects = new ArrayList<>();
        defObjects.addAll(jsonObjects);
        String string = "";
        for (JSONObject object : jsonObjects) {
            String InterConfigId = object.getString("InterConfigId");
            for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    string = "";
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        //一级属性
                        //注意 YdConfigId 对应的是 f字段对应的 id
                        if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                            defObjects.remove(object);//如果匹配上，则去掉
                            String interRadioReqs1 = object.getString("interRadioReqs");
                            List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                            declaredField.setAccessible(true);
                            try {
                                //获取选择的值 例如  实名中的可二次
                                Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                String oneValue = String.valueOf(o);
                                List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> Objects.equals(j.getString("YdConfigId"), oneValue)).collect(Collectors.toList());
                                String defaultValue = object.getString("defaultValue");
                                if (org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                    if (StringUtils.isNotEmpty(defaultValue)) {
                                        params.put("parameters["+InterConfigId+"]", defaultValue);
                                    }
                                }
                                if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                    JSONObject jsonObject2 = twoAttr.get(0);
                                    String interConfigId2 = jsonObject2.getString("InterConfigId");
                                    params.put("parameters["+InterConfigId+"]", interConfigId2);
                                }
                            } catch (Exception e) {
                                throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defObjects) {
            String id = object.getString("id");
            interRadioReqs = object.getString("interRadioReqs");
            jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
            for (JSONObject objects : jsonObjects) {
                if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                    params.put("parameters["+id+"]", objects.getString("defaultValue"));
                }
            }
        }
        //========================单选属性匹配结束=====================//
    }
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map<String,Object> params, String checkAttr) {
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        for (JSONObject object : checkJsonList) {
            String pf_ids = "";
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {

                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);
                        Object o = null;
                        try {
                            o = declaredField.get(goodsInfoAndAttrValueDto);
                        } catch (IllegalAccessException e) {
                            throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                        }
                        String oneValue = String.valueOf(o);
                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
                        //开始匹配二级属性
                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                        /**
                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                         */
                        for (JSONObject jsonObject1 : jsonObjects2) {
                            String[] split1 = oneValue.split(",");
                            String ydConfigId1 = jsonObject1.getString("YdConfigId");
                            if(StringUtils.isNotEmpty(ydConfigId1)) {
                                ydConfigId1 = ydConfigId1.replace(" ","");
                                for (String s : split1) {
                                    if (Objects.equals(s, ydConfigId1)) {
                                        String InterConfigId2 = jsonObject1.getString("InterConfigId");
                                        pf_ids += "," + InterConfigId2;
                                    }
                                }
                            }
                        }

                    }
                }
            }
            if (StringUtils.isNotEmpty(pf_ids)) {
                params.put("parameters["+object.getString("id")+"]", pf_ids.substring(1).trim());
            }else {
                params.put("parameters["+object.getString("id")+"]", "无");
            }
        }
    }
    /**
     * 开始匹配输入框属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param inputAttr
     */
    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map<String,Object> params, String inputAttr) {
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        String string = "";
        for (JSONObject object : jsonObjects1) {
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                string = "";
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String aavNameInter = object.getString("interName");
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            String oneValue = String.valueOf(o);
                            if (StringUtils.isNotEmpty(oneValue)) {
                                params.put("parameters["+object.getString("id")+"]", oneValue);
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            String id = object.getString("id");
            String defaultValue = object.getString("defaultValue");
            String name = object.getString("name");
            if (StringUtils.isNotEmpty(defaultValue)) {
                if(name.contains("账号")){
                    String substring = String.valueOf(System.currentTimeMillis()).substring(4);
                    if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getCarrierName())) {
                        if (goodsInfoAndAttrValueDto.getCarrierName().equals("微信")) {
                            substring = "VX" + substring;
                        }
                    }
                    params.put("parameters["+id+"]",substring);
                }else if(name.contains("密码")){
                    params.put("parameters["+id+"]","a"+goodsInfoAndAttrValueDto.getAccountPassword());
                }else if(name.contains("等级")){
                    params.put("parameters["+id+"]","30");
                }else {
                    params.put("parameters["+id+"]",0);
                }
            }
        }
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,SalePartner salePartner) {
        Map<String, Object> params = new TreeMap<>();
        params.put("transferProSupported","false");
        params.put("transferProtSign",0);
        params.put("supportCompensationService",2);
        params.put("showFaceCompensation",1);
        params.put("supportFaceCompensation",1);
        params.put("topicCardTimes","");
        params.put("topicCardIds","");
        params.put("unit","个");
        params.put("tradeType","js");
        params.put("cdkArray","");
        params.put("elecProtSign",0);
        params.put("recoverCompensForver",0);
        params.put("axgCompensation",1);
        params.put("authVideo",0);
        params.put("authVideoUrl","");
        params.put("idCardInHandUrl","");
        params.put("userPosition.deviceId","3301618982");
        params.put("userPosition.deviceName","Chrome");
        params.put("axgType","");
        params.put("axgServerFee","");
        params.put("axgConfId","");
        params.put("axgDays","");
        params.put("recycleFlag","");
        params.put("resellType","");
        params.put("recoverForeverServiceLimit","");
        params.put("qqAuthTaskId","");
        params.put("campSource","");
        params.put("campId","");
        params.put("campRoleId","");
        params.put("campTaskId","");
        String substring = salePartner.getSaleName();
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
        params.put("gameId",interAttr.getInterGameId());
        params.put("gameName",interAttr.getInterGameName());
        if ("枪战王者".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("groupId",0);
            params.put("groupName","全区");
            params.put("serverId",0);
            params.put("serverName","全服");
            if(regional.equals("安卓QQ")) {
                params.put("carrierId", "A5430Y003");
                params.put("carrierName", "安卓QQ");
            }else if(regional.equals("安卓微信")) {
                params.put("carrierId", "A5430Y004");
                params.put("carrierName", "安卓微信");
            }else if(regional.equals("苹果QQ")) {
                params.put("carrierId", "A5430Y005");
                params.put("carrierName", "苹果QQ");
            }else {
                params.put("carrierId", "A5430Y006");
                params.put("carrierName", "苹果微信");
            }
        }
        else if ("英雄联盟".equals(goodsInfoAndAttrValueDto.getGameName())) {
            params.put("axgCompensation",1);
            params.put("supportCompensationService",2);
            String qufu = "[{\"groupid\":\"G603P001\",\"groupname\":\"电信\",\"servers\":[{\"serverid\":\"G603P001001\",\"servername\":\"艾欧尼亚\"},{\"serverid\":\"G603P001002\",\"servername\":\"祖安\"},{\"serverid\":\"G603P001003\",\"servername\":\"诺克萨斯\"},{\"serverid\":\"G603P001004\",\"servername\":\"班德尔城\"},{\"serverid\":\"G603P001005\",\"servername\":\"皮尔特沃夫\"},{\"serverid\":\"G603P001006\",\"servername\":\"战争学院\"},{\"serverid\":\"G603P001007\",\"servername\":\"巨神峰\"},{\"serverid\":\"G603P001008\",\"servername\":\"雷瑟守备\"},{\"serverid\":\"G603P001009\",\"servername\":\"裁决之地\"},{\"serverid\":\"G603P001010\",\"servername\":\"黑色玫瑰\"},{\"serverid\":\"G603P001011\",\"servername\":\"暗影岛\"},{\"serverid\":\"G603P001012\",\"servername\":\"钢铁烈阳\"},{\"serverid\":\"G603P001013\",\"servername\":\"均衡教派\"},{\"serverid\":\"G603P001014\",\"servername\":\"水晶之痕\"},{\"serverid\":\"G603P001016\",\"servername\":\"影流\"},{\"serverid\":\"G603P001017\",\"servername\":\"守望之海\"},{\"serverid\":\"G603P001018\",\"servername\":\"征服之海\"},{\"serverid\":\"G603P001019\",\"servername\":\"卡拉曼达\"},{\"serverid\":\"G603P001020\",\"servername\":\"皮城警备\"}]},{\"groupid\":\"G603P002\",\"groupname\":\"网通\",\"servers\":[{\"serverid\":\"G603P002001\",\"servername\":\"比尔吉沃特\"},{\"serverid\":\"G603P002002\",\"servername\":\"德玛西亚\"},{\"serverid\":\"G603P002003\",\"servername\":\"弗雷尔卓德\"},{\"serverid\":\"G603P002004\",\"servername\":\"无畏先锋\"},{\"serverid\":\"G603P002005\",\"servername\":\"恕瑞玛\"},{\"serverid\":\"G603P002006\",\"servername\":\"扭曲丛林\"},{\"serverid\":\"G603P002007\",\"servername\":\"巨龙之巢\"}]},{\"groupid\":\"G603P003\",\"groupname\":\"体验区\",\"servers\":[{\"serverid\":\"G603P003001\",\"servername\":\"试炼之地\"}]},{\"groupid\":\"G603P005\",\"groupname\":\"全网络\",\"servers\":[{\"serverid\":\"G603P005001\",\"servername\":\"男爵领域\"},{\"serverid\":\"G603P005002\",\"servername\":\"峡谷之巅\"}]},{\"groupid\":\"G603P006\",\"groupname\":\"外服\",\"servers\":[{\"serverid\":\"G603P006001\",\"servername\":\"韩服\"},{\"serverid\":\"G603P006002\",\"servername\":\"欧服\"},{\"serverid\":\"G603P006003\",\"servername\":\"美服\"},{\"serverid\":\"G603P006004\",\"servername\":\"澳服\"},{\"serverid\":\"G603P006005\",\"servername\":\"台服\"},{\"serverid\":\"G603P006006\",\"servername\":\"日服\"}]},{\"groupid\":\"G603P007\",\"groupname\":\"教育网\",\"servers\":[{\"serverid\":\"G603P007001\",\"servername\":\"教育网专区\"}]}]\n";
            JSONArray jsonArray = JSONArray.parseArray(qufu);
            for(Object o: jsonArray){
                String groupid = JSONObject.parseObject(o.toString()).getString("groupid");
                String groupname = JSONObject.parseObject(o.toString()).getString("groupname");
                String servers = JSONObject.parseObject(o.toString()).getString("servers");
                JSONArray jsonArray1 = JSONArray.parseArray(servers);
                for(Object p : jsonArray1){
                    String serverid = JSONObject.parseObject(p.toString()).getString("serverid");
                    String servername = JSONObject.parseObject(p.toString()).getString("servername");
                    if(servername.equals(goodsInfoAndAttrValueDto.getServerName())){
                        params.put("groupId",groupid);
                        params.put("groupName",groupname);
                        params.put("serverId",serverid);
                        params.put("serverName",servername);
                        break;
                    }
                }
            }
        }
        else if ("英雄联盟(手游)".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("groupId",0);
            params.put("groupName","全区全服");
            params.put("serverId",0);
            params.put("serverName","全区全服");
            if(regional.equals("安卓QQ")) {
                params.put("carrierId", "A5654Y004");
                params.put("carrierName", "安卓QQ");
            }else if(regional.equals("安卓微信")) {
                params.put("carrierId", "A5654Y003");
                params.put("carrierName", "安卓微信");
            }else if(regional.equals("苹果QQ")) {
                params.put("carrierId", "A5654Y006");
                params.put("carrierName", "苹果QQ");
            }else {
                params.put("carrierId", "A5654Y005");
                params.put("carrierName", "苹果微信");
            }
        }
        else if ("金铲铲之战".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();


            if(regional.equals("苹果QQ")) {
                params.put("carrierId", "A5661Y001");
                params.put("carrierName", "QQ");
                params.put("groupId","A5661P002");
                params.put("groupName","苹果QQ区");
            }else if(regional.equals("安卓QQ")) {
                params.put("carrierId", "A5661Y001");
                params.put("carrierName", "QQ");
                params.put("groupId","A5661P004");
                params.put("groupName","安卓QQ区");
            }else if(regional.equals("苹果微信")) {
                params.put("carrierId", "A5661Y002");
                params.put("carrierName", "微信");
                params.put("groupId","A5661P003");
                params.put("groupName","苹果微信区");
            }else {
                params.put("carrierId", "A5661Y002");
                params.put("carrierName", "微信");
                params.put("groupId","A5661P005");
                params.put("groupName","安卓微信区");
            }

            params.put("serverId",0);
            params.put("serverName","全区全服");
        }
        else if ("暗区突围".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("groupId",0);
            params.put("groupName","全区全服");
            params.put("serverId",0);
            params.put("serverName","全区全服");
            if(regional.equals("安卓QQ")) {
                params.put("carrierId", "A5692Y004");
                params.put("carrierName", "安卓QQ");
            }else if(regional.equals("安卓微信")) {
                params.put("carrierId", "A5692Y005");
                params.put("carrierName", "安卓微信");
            }else if(regional.equals("苹果QQ")) {
                params.put("carrierId", "A5692Y006");
                params.put("carrierName", "苹果QQ");
            }else {
                params.put("carrierId", "A5692Y007");
                params.put("carrierName", "苹果微信");
            }
        }
        else if ("三角洲行动".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getCarrierName();
            params.put("groupId",0);
            params.put("groupName","全区全服");
            params.put("serverId",0);
            params.put("serverName","全区全服");
            if(regional.equals("QQ")) {
                params.put("carrierId", "A5776Y006");
                params.put("carrierName", "QQ");
            }else {
                params.put("carrierId", "A5776Y007");
                params.put("carrierName", "微信");
            }
        }
        else if ("使命召唤手游".equals(goodsInfoAndAttrValueDto.getGameName())) {
            String regional = goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("QQ")) {
                params.put("carrierId", "A5403B001");
                params.put("carrierName", "QQ");
                if(goodsInfoAndAttrValueDto.getSystemName().equals("安卓")) {
                    params.put("groupId", "A5403P002");
                    params.put("groupName", "安卓QQ区");
                    params.put("serverId", "A5403P002001");
                    params.put("serverName", "安卓QQ区");
                }else {
                    params.put("groupId", "A5403P004");
                    params.put("groupName", "安卓QQ区");
                    params.put("serverId", "A5403P004001");
                    params.put("serverName", "苹果QQ区");
                }
            }else {
                params.put("carrierId", "A5403B002");
                params.put("carrierName", "微信");
                if(goodsInfoAndAttrValueDto.getSystemName().equals("安卓")) {
                    params.put("groupId", "A5403P003");
                    params.put("groupName", "安卓微信区");
                    params.put("serverId", "A5403P003001");
                    params.put("serverName", "安卓微信区");
                }else {
                    params.put("groupId", "A5403P005");
                    params.put("groupName", "苹果微信区");
                    params.put("serverId", "A5403P005001");
                    params.put("serverName", "苹果微信区");
                }
            }
        }
        params.put("gtId","100003");
        params.put("goodsTypeName","账号");

        Property(params,goodsInfoAndAttrValueDto,salePartner);


        String title = goodsInfoAndAttrValueDto.getTitle();
        if (Objects.nonNull(title)) {
            if (title.length() > 190) {
                title = title.substring(0, 190);
            }
            params.put("title",title);
            params.put("inputTitle",title);
        }

        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String goodsImages = "";
        for(GoodsInfoImg goodsInfoImg1 : infoImgs){
            if(goodsInfoImg1.getImgUrl().contains("jpg")) {
                String img = uploadImg(goodsInfoImg1.getImgUrl());
                goodsImages += "зы" + img + "|其他";
            }
        }
        params.put("goodsImages",goodsImages.substring(2));
        params.put("machinePrintScreenCert",0);
        params.put("userPrintScreenCert",1);
        params.put("createIndexImageFlag","true");
        params.put("originPrice",goodsInfoAndAttrValueDto.getPrice());
        params.put("price",goodsInfoAndAttrValueDto.getPrice());
        params.put("phone",salePartner.getOther());
        params.put("qq",salePartner.getOther());
        params.put("tradeStartTime","00:00");
        params.put("tradeEndTime","24:00");
        params.put("designatedPurchase","2");
        params.put("allowBargin","1");
        params.put("acceptRecycle","1");
        params.put("effectiveDays-readonly","60天");
        params.put("effectiveDays","60");
        params.put("publishScopeFlag",0);
        params.put("deposit",0);
        params.put("withdrawCash",0);
        return params;
    }

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto,salePartner);
        String cover = MapUntils.getCover(params);
        cover = cover.substring(0,cover.length()-1);

        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body = RequestBody.create(mediaType, cover);
        Request request = new Request.Builder()
                .url("https://search.7881.com/publish")
                .method("POST", body)
                .addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9")
                .addHeader("Cache-Control", "max-age=0")
                .addHeader("Connection", "keep-alive")
                .addHeader("Content-Type", "application/x-www-form-urlencoded")
                .addHeader("Origin", "https://search.7881.com")
                .addHeader("Referer", "https://search.7881.com/publish.html?gameId=A2775&gameName=%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80%E5%AE%89%E5%8D%93%E7%89%88&gtId=100003&goodsTypeName=%E8%B4%A6%E5%8F%B7&groupId=0&groupName=%E5%85%A8%E5%8C%BA&serverId=0&serverName=%E5%85%A8%E6%9C%8D&carrierId=A2775B001&carrierName=QQ&camp=&platId=&platName=%E5%AE%89%E5%8D%93%E7%89%88")
                .addHeader("Sec-Fetch-Dest", "document")
                .addHeader("Sec-Fetch-Mode", "navigate")
                .addHeader("Sec-Fetch-Site", "same-origin")
                .addHeader("Sec-Fetch-User", "?1")
                .addHeader("Upgrade-Insecure-Requests", "1")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36")
                .addHeader("sec-ch-ua", "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
            .addHeader("Cookie", "__utma=66799784.1098069067.1736843507.1736843507.1736843507.1; __utmz=66799784.1736843507.1.1.utmcsr=i.7881.com|utmccn=(referral)|utmcmd=referral|utmcct=/; home_page_yxb=%7B%22gameid%22%3A%22G10%22%2C%22gamename%22%3A%22%E5%9C%B0%E4%B8%8B%E5%9F%8E%E4%B8%8E%E5%8B%87%E5%A3%AB%22%2C%22groupid%22%3A%22G10P001%22%2C%22serverid%22%3A%22G10P001001%22%2C%22groupserver%22%3A%22%E5%B9%BF%E4%B8%9C%E5%8C%BA%2F%E5%B9%BF%E4%B8%9C1%E5%8C%BA%22%2C%22tradeplace%22%3A%22%22%2C%22tradeplacename%22%3A%22%E4%BA%A4%E6%98%93%E6%96%B9%E5%BC%8F%22%2C%22camp%22%3A%22%22%2C%22refresh%22%3A%221%22%7D; SERVERID=248; PUBLISH_AGREEMENT=1745218742496; IsShowGuideTip=2; Hm_lvt_6fb35abaf76325a4316e33e23c984e73=1744446651,1745909732,1746599509; HMACCOUNT=3309EA28EF2272B8; home_page_search=%7B%22gameid%22%3A%22A2775%22%2C%22goodschannel%22%3A%22100003%22%2C%22carrierid%22%3A%22A2775B002%22%2C%22camp%22%3Anull%7D; login.risk.cookie=d80e9159-8315-4efc-9f45-37b363ece74c; AUTHTICKETCHECKVALUE=W9Dv9bfHb6Ozv5Iij8B0ivLD9zeZVOqdAptey4BJq%2F5JdjeSLmtoDZf6KNU4F2sHMB3Zn06RGPX8%0AMHiBP8oYjuK%2FPoI5DfS7hLodrUEd4unrCKwZo%2FUFFoDV86hBtg9urN7l3wRY9WTSioN8CHuHG4xL%0AIhdhlUWnys5K1IGvps4%3D; Authorization=\""+salePartner.getThreeOther().replace("\"","")+"\"; returnUrl=\"http://www.7881.com/common/game/js/game_base_info.js\"; Hm_lpvt_6fb35abaf76325a4316e33e23c984e73=1746857343")
                .build();
        String response = "";
        try {
            Response responses = client.newCall(request).execute();
            response = responses.toString();
//            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if(StringUtils.isNotEmpty(response)) {
            if(!response.contains("err")){
                result.put("code", 200);
                if(response.contains("goodsId")) {
                    String goodsId = response.substring(response.indexOf("goodsId=") + 8, response.indexOf("&supportRepublish"));
                    result.put("outId", goodsId);
                }
            }else {
                result.put("code", 500);
            }
            result.put("req", JSONObject.toJSONString(params));
            result.put("msg", response);
            result.put("res", response);
        }else {
            result.put("req", JSONObject.toJSONString(params));
            result.put("msg", "密钥已失效,请及时替换");
            result.put("res", "密钥已失效,请及时替换");
        }
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,
                               SalePartner salePartner) {
        Map<String, Object> params = new HashMap<>();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        params.put("goodsId",artRecs.get(0).getOutid());
        params.put("pernum",1);
        params.put("price",goodsInfoAndAttrValueDto.getPrice());
        params.put("originPrice",goodsInfoAndAttrValueDto.getPrice());
        params.put("type",1);
        String response = HttpRequest.post("https://gw.7881.com/goods-service-api/api/user-goods/price-stock/modify")
                .header("Authorization",salePartner.getThreeOther().replace("\"",""))
                .body(JSONObject.toJSONString(params)).execute().body();

        JSONObject jsonObject1 = JSONObject.parseObject(response);
        System.out.println("请求参数:"+JSONObject.toJSONString(params));
        System.out.println("响应参数:"+response);
        Map<String, Object> result = new HashMap<>();
        if(jsonObject1.getString("code").equals("0")){
            result.put("code", 200);
        }else {
            result.put("code", 500);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("msg", response);
        result.put("res", response);
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {

        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);

        String response = HttpRequest.get("https://gw.7881.com/goods-service-api/api/user-goods/off-sale?goodsId="+artRecs.get(0).getOutid())
                .header("Authorization",salePartner.getThreeOther().replace("\"",""))
                .execute().body();

        JSONObject jsonObject1 = JSONObject.parseObject(response);
        System.out.println("请求参数:"+JSONObject.toJSONString(artRecs.get(0).getOutid()));
        System.out.println("响应参数:"+response);
        Map<String, Object> result = new HashMap<>();
        if(jsonObject1.getString("code").equals("0")){
            result.put("code", 200);
            //删除
            HttpRequest.get("https://gw.7881.com/goods-service-api/api/user-goods/delete?goodsId="+artRecs.get(0).getOutid())
                    .header("Authorization",salePartner.getThreeOther().replace("\"",""))
                    .execute().body();
        }else {
            result.put("code", 500);
        }
        result.put("req", JSONObject.toJSONString(artRecs.get(0).getOutid()));
        result.put("msg", response);
        result.put("res", response);
        return AjaxResult.success(result);
    }

    /**
     * 通用 比对方法 取第一个并返回
     *
     * @param str1
     * @param str2
     * @return
     */
    String biGetFirst(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (str2.replace("贵族", "V").toUpperCase().replace("IP", "").contains(s)) {
                res = s;
                break;
            }
        }
        return res;
    }

    /**
     * 英雄联盟 段位 比对方法 取第一个并返回 为了不跟其他游戏比较相互影响单拉出来
     *
     * @param str1
     * @param str2
     * @return
     */
    String yxlmdwbiGetFirst(String str1, String str2) {
        //黑铁,黄铜,白银,黄金,铂金,钻石,大师,宗师,王者
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            String a = s;
            if (str2.contains(a)) {
                res = s;
                break;
            }
        }
        return res;
    }

    /**
     * 通用 比对方法 比对成功加上
     *
     * @param str1
     * @param str2
     * @return
     */
    String biGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        boolean is = false;
        for (String s : str1sz) {
            if (str2.replace("·", "")
                    .replace("(", "")
                    .replace(")", "")
                    .replace("角色-", "").contains(s.replace("·", "")
                            .replace("(", "")
                            .replace(")", "")
                            .replace("角色-", ""))) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }

    /**
     * 穿越火线端游 比对方法 比对成功加上 为了不跟其他游戏比较相互影响单拉出来
     *
     * @param str1
     * @param str2
     * @return
     */
    String CyhxCFbiGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        boolean is = false;
        for (String s : str1sz) {
            if (str2.replace("·", "")
                    .replace("(", "")
                    .replace(")", "")
                    .replace("-", "")
                    .contains(s.replace("·", "")
                            .replace("(", "")
                            .replace(")", "")
                            .replace("-", ""))) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }

    /**
     * 根据游戏id获取该游戏信息
     *
     * @param gameid
     */
    static void getGameInfo(String gameid, SalePartner salePartner) {
        String gtId = "100003";
        String result = null;
        try {
            result = LieBaoCore.get_game_info(gameid, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(result);
    }


    /**
     * 根据游戏id获取该游戏垂直属性
     *
     * @param gameid
     */
    static void getGameVertiacl(String gameid, SalePartner salePartner) {
        String gtId = "100003";
        String result = null;
        try {
            result = LieBaoCore.get_gamegt_vertical(gameid, gtId, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(result);
    }

    /**
     * 根据商品id进行下架
     *
     * @param goodsId
     * @param salePartner
     * @return
     * @throws Exception
     */
    ResultEntity shangpinxiajia(Long[] goodsId, SalePartner salePartner) throws Exception {
        Map params = new HashMap<>();
        params.put("goodsId", goodsId);
        params.put("userId", salePartner.getThreeOther());
        params.put("enforce", "true");
        params.put("closedReason", 0);
        ResultEntity resultEntity = LieBaoCore.cp_goods_pull_off(params, salePartner);
        return resultEntity;
    }

    /**
     * 根据商品id进行删除
     *
     * @param goodsId
     * @param salePartner
     * @return
     * @throws Exception
     */
    ResultEntity shangpinshanchu(Long[] goodsId, SalePartner salePartner) throws Exception {
        Map params = new HashMap<>();
        params.put("goodsId", goodsId);
        params.put("userId", salePartner.getThreeOther());
        ResultEntity resultEntity = LieBaoCore.cp_goods_delete(params, salePartner);
        return resultEntity;
    }


    /**
     * 封装 王者荣耀 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean wzryInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        WzryInfo wzryInfo = new WzryInfo();
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setGameId("A2775");
                goodsBean.setCarrierId("A2775B001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A2775P003");
                goodsBean.setServerId("A2775P003001");
                wzryInfo.setCode7("正式服");
                break;
            case "安卓微信":
                goodsBean.setGameId("A2775");
                goodsBean.setCarrierId("A2775B002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A2775P034");
                goodsBean.setServerId("A2775P034001");
                wzryInfo.setCode7("正式服");
                break;
            case "苹果QQ":
                goodsBean.setGameId("A2705");
                goodsBean.setCarrierId("A2705Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A2705P003");
                goodsBean.setServerId("A2705P003001");
                wzryInfo.setCode8("正式服");
                break;
            case "苹果微信":
                goodsBean.setGameId("A2705");
                goodsBean.setCarrierId("A2705Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A2705P011");
                goodsBean.setServerId("A2705P011001");
                wzryInfo.setCode8("正式服");
                break;
        }
        //账号 y
        wzryInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        wzryInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(wzryInfo);
        return goodsBean;
    }

    /**
     * 封装 和平精英 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean hpjyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        HpjyInfo hpjyInfo = new HpjyInfo();
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setGameId("A5454");
                goodsBean.setCarrierId("A5454Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5454P001");
                goodsBean.setServerId("A5454P001001");
                break;
            case "安卓微信":
                goodsBean.setGameId("A5454");
                goodsBean.setCarrierId("A5454Y001");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5454P002");
                goodsBean.setServerId("A5454P002001");
                break;
            case "苹果QQ":
                goodsBean.setGameId("A5455");
                goodsBean.setCarrierId("A5455Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5455P001");
                goodsBean.setServerId("A5455P001001");
                break;
            case "苹果微信":
                goodsBean.setGameId("A5455");
                goodsBean.setCarrierId("A5455Y001");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5455P002");
                goodsBean.setServerId("A5455P002001");
                break;
        }
        //账号 y
        hpjyInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        hpjyInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(hpjyInfo);
        return goodsBean;
    }

    /**
     * 封装 英雄联盟端游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean yxlmInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G603");
        YxlmInfo yxlmInfo = new YxlmInfo();
        //区服
        String yxlmqf = "峡谷之巅=G603P005002--G603P005,班德尔城=G603P001004--G603P001,日服=G603P006006--G603P006,均衡教派=G603P001013--G603P001,钢铁烈阳=G603P001012--G603P001,扭曲丛林=G603P002006--G603P002,欧服=G603P006002--G603P006,皮城警备=G603P001020--G603P001,试炼之地=G603P003001--G603P003,征服之海=G603P001018--G603P001,黑色玫瑰=G603P001010--G603P001,巨神峰=G603P001007--G603P001,水晶之痕=G603P001014--G603P001,韩服=G603P006001--G603P006,台服=G603P006005--G603P006,弗雷尔卓德=G603P002003--G603P002,无畏先锋=G603P002004--G603P002,皮尔特沃夫=G603P001005--G603P001,战争学院=G603P001006--G603P001,雷瑟守备=G603P001008--G603P001,艾欧尼亚=G603P001001--G603P001,恕瑞玛=G603P002005--G603P002,教育网专区=G603P001015--G603P001,暗影岛=G603P001011--G603P001,卡拉曼达=G603P001019--G603P001,男爵领域=G603P005001--G603P005,美服=G603P006003--G603P006,裁决之地=G603P001009--G603P001,守望之海=G603P001017--G603P001,澳服=G603P006004--G603P006,巨龙之巢=G603P002007--G603P002,诺克萨斯=G603P001003--G603P001,德玛西亚=G603P002002--G603P002,影流=G603P001016--G603P001,祖安=G603P001002--G603P001,比尔吉沃特=G603P002001--G603P002";

        Map qdqMap = stringTOmap(yxlmqf);
        if (Objects.nonNull(qdqMap.get(goodsInfoAndAttrValueDto.getServerName()))) {
            String qu = qdqMap.get(goodsInfoAndAttrValueDto.getServerName()).toString();
            goodsBean.setGroupId(qu.split("--")[1].trim());
            goodsBean.setServerId(qu.split("--")[0].trim());
        } else {
            throw new GlobalException(goodsInfoAndAttrValueDto.getThirdId() + "英雄联盟大区未找到");
        }
        yxlmInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        yxlmInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(yxlmInfo);
        return goodsBean;
    }

    /**
     * 封装 穿越火线端游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean cyhxCFInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G68");
        String cyhxCFQF = "浙江二区=G68P001020--G68P001,安徽一区=G68P001019--G68P001,北京四区=G68P002007--G68P002,上海二区=G68P001009--G68P001,湖南二区=G68P006009--G68P006,江苏二区=G68P001024--G68P001,湖北二区=G68P006002--G68P006,广东二区=G68P006004--G68P006,辽宁三区=G68P002005--G68P002,山东二区=G68P002015--G68P002,湖南一区=G68P006008--G68P006,河南一区=G68P002009--G68P002,湖北一区=G68P006001--G68P006,广东一区=G68P006003--G68P006,北京二区=G68P002003--G68P002,河北一区=G68P002013--G68P002,广东四区=G68P006006--G68P006,广西一区=G68P006011--G68P006,北京一区=G68P002002--G68P002,云南一区=G68P005005--G68P005,河南二区=G68P002016--G68P002,南方大区=G68P006007--G68P006,陕西一区=G68P005001--G68P005,重庆一区=G68P005002--G68P005,辽宁一区=G68P002001--G68P002,移动专区=G68P001025--G68P001,吉林一区=G68P002012--G68P002,辽宁二区=G68P002004--G68P002,教育网专区=G68P001026--G68P001,江西一区=G68P006010--G68P006,广东三区=G68P006005--G68P006,北京三区=G68P002006--G68P002,山东一区=G68P002010--G68P002,江苏一区=G68P001018--G68P001,福建一区=G68P001001--G68P001,浙江一区=G68P001002--G68P001,黑龙江区=G68P002011--G68P002,四川二区=G68P005004--G68P005,上海一区=G68P001008--G68P001,四川一区=G68P005003--G68P005,北方大区=G68P002008--G68P002,山西一区=G68P002014--G68P002";
        Map cyhxCFQFMap = stringTOmap(cyhxCFQF);
        if (Objects.nonNull(cyhxCFQFMap.get(goodsInfoAndAttrValueDto.getServerName()))) {
            String qu = cyhxCFQFMap.get(goodsInfoAndAttrValueDto.getServerName()).toString();
            goodsBean.setGroupId(qu.split("--")[1].trim());
            goodsBean.setServerId(qu.split("--")[0].trim());
        } else {
            throw new GlobalException(goodsInfoAndAttrValueDto.getThirdId() + "英雄联盟大区未找到");
        }
        CyhxCFInfo cyhxCFInfo = new CyhxCFInfo();
        cyhxCFInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        cyhxCFInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(cyhxCFInfo);
        return goodsBean;
    }

    /**
     * 封装 穿越火线手游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean cyhxQZWZInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        CyhxQZWZInfo cyhxQZWZInfo = new CyhxQZWZInfo();
        goodsBean.setGameId("A5430");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5430Y003");
                goodsBean.setCarriername("安卓QQ");
                goodsBean.setGroupId("A5430P002");
                goodsBean.setServerId("A5430P002001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5430Y004");
                goodsBean.setCarriername("安卓微信");
                goodsBean.setGroupId("A5430P004");
                goodsBean.setServerId("A5430P004001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5430Y005");
                goodsBean.setCarriername("苹果QQ");
                goodsBean.setGroupId("A5430P001");
                goodsBean.setServerId("A5430P001001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5430Y006");
                goodsBean.setCarriername("苹果微信");
                goodsBean.setGroupId("A5430P003");
                goodsBean.setServerId("A5430P003001");
                break;
        }

        cyhxQZWZInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        cyhxQZWZInfo.setGamepassword(goodsInfoAndAttrValueDto.getAccountPassword());
        cyhxQZWZInfo.setGamepasswordqr(goodsInfoAndAttrValueDto.getAccountPassword());
        goodsBean.setPropertyList(cyhxQZWZInfo);
        return goodsBean;
    }

    /**
     * 封装 原神 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean ysInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5653");
        switch (goodsInfoAndAttrValueDto.getServerName()) {
            case "天空岛":
                goodsBean.setCarrierId("A5653Y001");
                goodsBean.setCarriername("游戏官方");
                goodsBean.setGroupId("A5653P001");
                goodsBean.setServerId("A5653P001001");
                break;
            case "世界树":
                goodsBean.setCarrierId("A5653Y002");
                goodsBean.setCarriername("哔哩哔哩");
                goodsBean.setGroupId("A5653P002");
                goodsBean.setServerId("A5653P002001");
                break;
        }
        YsInfo ysInfo = new YsInfo();
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF9())){
            if(!"null".equals(goodsInfoAndAttrValueDto.getF9())){
                ysInfo.setGameuid(goodsInfoAndAttrValueDto.getF9());
            }else {
                ysInfo.setGameuid(String.valueOf(System.currentTimeMillis()).substring(3));
            }
        }else {
            ysInfo.setGameuid(String.valueOf(System.currentTimeMillis()).substring(3));
        }
        ysInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        ysInfo.setGamepassword("123456");
        ysInfo.setGamepasswordqr("123456");
        goodsBean.setPropertyList(ysInfo);
        return goodsBean;
    }
    YX7881GoodsBean hyrzInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5468");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5468Y004");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5468P001");
                goodsBean.setServerId("A5468P001001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5468Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5468P003");
                goodsBean.setServerId("A5468P003001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5468Y006");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5468P002");
                goodsBean.setServerId("A5468P002001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5468Y005");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5468P004");
                goodsBean.setServerId("A5468P004001");
                break;
        }
        HyrzInfo hyrzInfo = new HyrzInfo();
        hyrzInfo.setGameaccount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountNumber())?goodsInfoAndAttrValueDto.getAccountNumber():goodsInfoAndAttrValueDto.getId()+"");
        hyrzInfo.setGamepassword(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        hyrzInfo.setGamepasswordqr(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        hyrzInfo.setAntiaddiction("无防沉迷");
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF7())){
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF7()));
            if(gameAttribute1.getFieldName().equals("可改二次")){
                hyrzInfo.setCanSecond("可二次");
            }else {
                hyrzInfo.setCanSecond("不可二次");
            }
        }else {
            hyrzInfo.setCanSecond("不可二次");
        }
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF5())){
            List<GameAttribute> gameAttributs = getGameAttributs(goodsInfoAndAttrValueDto.getF5());
            String[] srz = "漩涡鸣人「九喇嘛连结」,春野樱「忍界大战」,自来也,自来也「仙人模式」,自来也「舞之豪杰」,大蛇丸,纲手,纲手「百豪」,迈特凯「死门」,波风水门,波风水门「秽土转生」,猿飞日斩,猿飞日斩「秽土转生」,千手扉间,千手扉间「秽土转生」,千手柱间,千手柱间「秽土转生」,宇智波斑,宇智波斑「秽土转生」,宇智波斑「木叶创立」,宇智波鼬「须佐能乎」,宇智波鼬「秽土转生」,神秘面具男,宇智波斑「白面具」,宇智波带土「忍界大战」,神秘面具男「红夜之刃」,罗砂「四代目风影」,三代目风影「秽土转生」,鬼灯幻月「二代目水影」,艾「四代目雷影」,艾「三代目雷影」,金角银角「秽土转生」,大野木「三代目土影」,大野木「忍界大战」,无「二代目土影」,半藏「秽土转生」,佩恩「天道」,佩恩·天道「超」,长门「秽土转生」,药师兜「仙人模式」,大筒木金式,宇智波佐助「永恒万花筒」".split(",");
            String code = "";
            for(GameAttribute gameAttribute1 : gameAttributs){
                for(String s : srz){
                    if(onlyHanZi(gameAttribute1.getFieldName()).equals(onlyHanZi(s))){
                        code+=","+s;
                    }
                }
            }
            if(StringUtils.isNotEmpty(code)){
                hyrzInfo.setCode1(code.substring(1));
            }else {
                hyrzInfo.setCode1("无S级忍者");
            }
        }else {
            hyrzInfo.setCode1("无S级忍者");
        }
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF6())){
            List<GameAttribute> gameAttributs = getGameAttributs(goodsInfoAndAttrValueDto.getF6());
            String[] srz = "神秘面具男「忍者之路」,宇智波佐助「疾风传咒印」,天天「忍界大战」,旗木卡卡西,旗木卡卡西「忍界大战」,旗木卡卡西「元气夏日」,迈特凯「惊门」,迈特凯「忍界大战」,猿飞阿斯玛「七夕限定」,宇智波止水「新春限定」,志村团藏,猿飞日斩「火影继承人」,猿飞日斩「三忍之师」,波风水门「新春限定」,勘九郎「忍界大战」,照美冥「夏日泳装」,照美冥「侠隐江湖」,桃地再不斩「漂泊武士」,千手扉间「漂泊武士」,达鲁伊,三船「青年」,三船,纲手「侠隐江湖」,佩恩·六道「漂泊浪客」,小南「夏日泳装」,小南「新春限定」,绝,蝎「百机操演」,蝎「晓创生」,宇智波鼬「新春限定」,干柿鬼鲛「鲛肌融合」,迪达拉「新春限定」,阿飞,飞段「恶灵之影」,飞段「晓创生」,宇智波带土「暴怒」,黄土「忍界大战」,卑留呼「火之意志继承者」,漩涡鸣人「第四尾」".split(",");
            String code = "";
            for(GameAttribute gameAttribute1 : gameAttributs){
                for(String s : srz){
                    if(onlyHanZi(gameAttribute1.getFieldName()).equals(onlyHanZi(s))){
                        code+=","+s;
                    }
                }
            }
            if(StringUtils.isNotEmpty(code)){
                hyrzInfo.setCode1(code.substring(1));
            }else {
                hyrzInfo.setCode1("无A级忍者");
            }
        }else {
            hyrzInfo.setCode1("无A级忍者");
        }
        hyrzInfo.setCode3("无");
        hyrzInfo.setCode8("0");
        goodsBean.setPropertyList(hyrzInfo);
        return goodsBean;
    }

    YX7881GoodsBean wwqyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G5706");

        goodsBean.setCarrierId("G5706B001");
        goodsBean.setCarriername("QQ账号");

        goodsBean.setGroupId("G5706P001");
        goodsBean.setServerId("G5706P001001");

        goodsBean.setGroupId("G5706P001");
        goodsBean.setServerId("G5706P001001");
        WwqyInfo wwqyInfo = new WwqyInfo();
        wwqyInfo.setCarrier_name("QQ账号");
        wwqyInfo.setAccountType(goodsInfoAndAttrValueDto.getGroupName()+"账号");
        wwqyInfo.setAccountSource("我是号主");
        wwqyInfo.setAntiaddiction("无防沉迷");
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())) {
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
            if(gameAttribute1.getFieldName().equals("可二次实名")) {
                wwqyInfo.setCanSecond("可二次");
            }else {
                wwqyInfo.setCanSecond("不可二次");
            }
        }
        wwqyInfo.setWwds("0");
        wwqyInfo.setYjds("0");
        wwqyInfo.setAccountDan("暂无段位");
        wwqyInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        wwqyInfo.setGamepassword("wenkefu");
        wwqyInfo.setGamepasswordqr("wenkefu");
        goodsBean.setPropertyList(wwqyInfo);
        return goodsBean;
    }

    YX7881GoodsBean yxlmsyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5654");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5654Y004");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5654P004");
                goodsBean.setServerId("A5654P004001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5654Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5654P006");
                goodsBean.setServerId("A5654P006001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5654Y006");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5654P005");
                goodsBean.setServerId("A5654P005001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5654Y005");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5654P007");
                goodsBean.setServerId("A5654P007001");
                break;
        }
        YxlmsyInfo yxlmsyInfo = new YxlmsyInfo();
        yxlmsyInfo.setGameaccount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountNumber())?goodsInfoAndAttrValueDto.getAccountNumber():goodsInfoAndAttrValueDto.getId()+"");
        yxlmsyInfo.setGamepassword(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        yxlmsyInfo.setGamepasswordqr(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        yxlmsyInfo.setAntiaddiction("无防沉迷");
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF4())){
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF4()));
            if(gameAttribute1.getFieldName().equals("可二次实名")){
                yxlmsyInfo.setCode6("可二次");
            }else {
                yxlmsyInfo.setCode6("不可二次");
            }
        }else {
            yxlmsyInfo.setCode6("不可二次");
        }
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())){
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
            String[] string = "黄铜,白银,黄金,铂金,翡翠,钻石,大师,宗师,王者".split(",");
            for(String s : string){
                if(gameAttribute1.getFieldName().contains(s)){
                    yxlmsyInfo.setSelect(s);
                    break;
                }
            }
        }else {
            yxlmsyInfo.setSelect("暂无段位");
        }
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())){
            List<GameAttribute> gameAttributs = getGameAttributs(goodsInfoAndAttrValueDto.getF2());
            String[] string = "暗星尊烬,地狱之门卫士加里奥,炼狱魔犬内瑟斯,女主播迦娜,星域游侠崔斯特,战斗学院伊泽瑞尔,星之守护者金克丝,源计划：联合艾希,神王德莱厄斯,神王盖伦,KDA萨勒芬妮".split(",");
            String code = "";
            for(GameAttribute gameAttribute1 : gameAttributs){
                for(String s : string){
                    if(gameAttribute1.getFieldName().contains(s)){
                        code+=","+s;
                    }
                }
            }
            if(StringUtils.isNotEmpty(code)){
                yxlmsyInfo.setCode1(code.substring(1));
            }else {
                yxlmsyInfo.setCode1("无");
            }
        }else {
            yxlmsyInfo.setCode1("无");
        }
        yxlmsyInfo.setLevel("问客服");
        yxlmsyInfo.setHeroCount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF5())?goodsInfoAndAttrValueDto.getF5():"0");
        yxlmsyInfo.setCode7(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF6())?goodsInfoAndAttrValueDto.getF6():"0");
        goodsBean.setPropertyList(yxlmsyInfo);
        return goodsBean;
    }
    //只保留中文
    private String onlyHanZi(String str) {
        String reg = "[^\u4e00-\u9fa5]";
        str = str.replaceAll(reg, "");
        return str;
    }

    private String getPropertyParam(String content, String param) {
        if (StringUtils.isNotEmpty(param)) {
            List<GameAttribute> gameAttributes = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(param.split(","), Long.class));
            if (CollectionUtils.isNotEmpty(gameAttributes)) {
                List<String> split = Arrays.asList(content.split(","));
                List<String> collect = gameAttributes.stream().map(s -> s.getFieldName()).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    StringBuilder builder = new StringBuilder();
                    for (String s : collect) {
                        if (split.contains(s)) {
                            builder.append(s + ",");
                        }
                    }
                    if (builder.length() > 0) {
                        String substring = builder.substring(0, builder.length() - 1);
                        return substring;
                    }
                }
            }
        }
        return "无";
    }

    public static File convert(byte[] byteArray,String s) throws IOException {
        File file = File.createTempFile(s.substring(0,13), ".jpg");
//        imgUrl = file.getPath();
        Path path = Paths.get(file.getAbsolutePath());
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(byteArray);
        }catch (Exception e){

        }
        return file;
    }
    public static void main(String[] args) {
        String s = "https://search.7881.com/publish/result.html?gameId=G603&gtId=100003&code=0&goodsId=201612571374232&supportRepublish=true&batchPublishFlag=false";
        String substring = s.substring(s.indexOf("goodsId=")+8,s.indexOf("&supportRepublish"));
        System.out.println(substring);
    }

    String uploadImg(String img){
        String string = DigestUtils.md5Hex(img);
        File file = null;
        try {
            URL url = new URL(img);
            BufferedImage image = ImageIO.read(url.openStream());
            byte[] bytes = ImgUntil.bufferedImageToByteArray(image);
//            long srcSize = bytes.length;
//            if (srcSize / 1024 > 5000) {
//                bytes = ImgUntilYS.compressPicForScale(bytes, 3072l);
//            } else {
//                bytes = ImgUntilYS.compressPicForScale(bytes, 2048l);
//            }
            file = convert(bytes,string);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String fileImage = HttpRequest.post("https://upload.7881.com/file/goodsUploadFlash.action?pathType=10004").form("isGoods","true")
                .form("id","WU_FILE_0")
                .form("size","192402").form("type","image/jpeg").form("fileImage", file).execute().body();
        String string1 = JSONObject.parseObject(fileImage).getString("url");
        return string1;
    }

    /**
     * String字符串的值 =号拼接 转Map
     *
     * @param b
     * @return
     */
    Map stringTOmap(String b) {
        if (StringUtils.isNotEmpty(b)) {
            b = b.replaceAll(" ", "");
        }
        Map docType = new HashMap();
        StringTokenizer items;
        for (StringTokenizer entrys = new StringTokenizer(b, ","); entrys.hasMoreTokens();
             docType.put(items.nextToken(), items.hasMoreTokens() ? ((Object) (items.nextToken())) : null)) {
            items = new StringTokenizer(entrys.nextToken(), "=");
        }
        return docType;
    }


    // 以下为新写的方法
    private String reRedioValue(String value) {
        String reStr = "";
        if (StringUtils.isNotEmpty(value)) {
            GameAttribute gameAttribute =
                    gameAttributeService.selectGameAttributeById(Long.valueOf(value));
            if (gameAttribute != null) {
                if (StringUtils.isNotEmpty(gameAttribute.getFieldName())) {
                    reStr = gameAttribute.getFieldName();
                }

            }
        }
        return reStr;
    }

    String baohan(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (s.contains(str2)) {
                res = s;
                break;
            }
        }
        return res;
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        if (StringUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    String baohanGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (str2.contains(s)) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }


}